/**
 * 
 */
package com.roshan.service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.stereotype.Service;

/**
 * @author roshan
 * 
 */
@Service
@SuppressWarnings("nls")
public class NotificationService implements INotificationService {

    private final Logger logger = Logger.getLogger(getClass());

    @Autowired
    private final SimpleMailMessage mailMessage = null;

    @Autowired
    private final MailEngine mailEngine = null;

    @Override
    public void sendSignUpSuccessMail(String email, String fullName, String username, String notMaskedPassword, String appName,
            String message, String url, String templateName, Locale locale) {

        try {
            this.logger.debug("Sending e-mail to user [" + email + "]...");

            this.mailMessage.setTo(fullName + "<" + email + ">");
            this.mailMessage.setSubject("User Registration : " + appName);

            Map<String, Serializable> model = new HashMap<String, Serializable>();

            // TODO: once you figure out how to get the global resource bundle in
            // WebWork, then figure it out here too. In the meantime, the Username
            // and Password labels are hard-coded into the template.
            // model.put("bundle", getTexts());

            model.put("message", message);
            model.put("applicationURL", url);
            model.put("username", username);
            model.put("notMaskedPassword", notMaskedPassword);
            this.mailEngine.sendMessage(this.mailMessage, templateName, model);

        } catch (Exception e) {
            this.logger.error("Error occured while sending the email", e);
        }
    }

}
